﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Bluyel.Core;

namespace Bluyel_Samples_VS10
{
    /// <summary>
    /// Code samples to see how to create:
    /// Var/Const Data Structure with members Phy Length types.
    /// </summary>
    public class Sample_VarConst_Struct_M_PhyLength
    {
        //---------------------------------------------------------------------
        /// <summary>
        /// Create a struct with an int as member.
        /// </summary>
        public void CreateStruct_M_String_PhyLength()
        {
            Console.WriteLine("\n----Create a data struct with members:\n");

            // create the core and define all built-in types
            BluyelCore core = new BluyelCore();
            core.TypeBuilder.DefineAllTypes();

            // Create a var data structure, with some data basic type  
            // struct st
            //   String s= 'Width'
            //   PhyLength w = 327m
            // end
            Console.WriteLine("Create a data structure:");
            Console.WriteLine("Struct st\n  String s ='Width'\n  PhyLength = 327m\nend");
            IDStruct dataSt = core.DataBuilder.CreateVarStruct("st");

            // add members
            DString varSt_s = core.DataBuilder.AddVarStructMemberString(dataSt, "s", "hello");
            IDPhyLength varSt_w = core.DataBuilder.AddVarStructMemberPhyLength(dataSt, "w", 327, TypePhyLengthPrefix.Metre);

            Console.WriteLine("Member count=" + dataSt.ListData.Count());

            // display members
            Console.WriteLine("\nDisplay Members:");
            foreach (IDataNamed data in dataSt.ListData)
            {
                if(data is DPhyLength)
                    Console.WriteLine("Type= " + data.Type.Name + ", Name: " + data.Name + "= " + (data as DPhyLength).DVal.Value + " " + (data as DPhyLength).DVal.Prefix);

                if(data is DString)
                    Console.WriteLine("Type= " + data.Type + ", Name: " + data.Name + "= '" + (data as DString).Val + "'");
            }
        }

    }
}
